package com.example.kafka.controller;

import com.alibaba.fastjson.JSON;
import com.example.kafka.dto.UserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SendController {
    @Autowired
    private KafkaTemplate<String, Object> kafkaTemplate;

    @GetMapping("/send")
    public String send(Integer age) {
        UserDto dto = new UserDto();
        dto.setName("hhh");
        dto.setAge(age);
        kafkaTemplate.send("statistic_topic", JSON.toJSONString(dto));
        return "hello";
    }
}
